const equal = require('../utils/equal');
const Mock = require('mockjs');

const ACCOUNT = {
  PhoneNumber: 12345678901,
  Password: 'pwd',
  CompanyName: '登录成功有限公司',
  CompanyAddress: '登录成功公司地址'
}

function getCompanyName (companyName) {
  const { Random } = Mock;
  let list = [];
  let randomNumber = Math.ceil(Math.random() * 10);
  for (let i = 0; i < randomNumber; i++) {
    let item = Mock.mock({
      'CompanyName|1': [
        `${companyName}${Random.cword(4, 6)}科技有限公司`,
        `${companyName}${Random.cword(3, 5)}股份有限公司`,
      ]
    })
    list.push(item);
  }

  return list;
}

function login (requestData) {
  const { Random } = Mock;
  if (equal(requestData, ACCOUNT)) {
    return Mock.mock({
      'Token': Random.guid(),
      'UserID': Random.guid(),
      'UserName': ACCOUNT.CompanyName,
      'UserPhone': ACCOUNT.PhoneNumber
    });
  } else {
    return { errMsg: 'Incorrect phoneNumber or password.' }
  }
}


module.exports = {
  getCompanyName,
  login
}